package dataBase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GetColumnsAsListsFromDB {
	private static PreparedStatement statement;

	static List<String> getExistingUserNamesAsList(Connection dbCon)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("SELECT username FROM users ORDER BY user_id");
		ResultSet result = statement.executeQuery();

		List<String> usernames = new ArrayList<String>();

		while (result.next()) {
			usernames.add(result.getString("username"));
		}
		return usernames;
	}

	static List<String> getExistingPasswordsAsList(Connection dbCon)
			throws SQLException, ClassNotFoundException {
		statement = dbCon
				.prepareStatement("SELECT password FROM users ORDER BY user_id");
		ResultSet result = statement.executeQuery();

		List<String> passwords = new ArrayList<String>();

		while (result.next()) {
			passwords.add(result.getString("password"));
		}
		return passwords;
	}

	static List<String> getExistingTableNamesAsList(Connection dbCon)
			throws SQLException {
		statement = dbCon
				.prepareStatement("SELECT table_name FROM user_tables");
		ResultSet result = statement.executeQuery();

		List<String> tableList = new ArrayList<String>();

		while (result.next()) {
			tableList.add(result.getString("table_name"));
		}
		return tableList;
	}
}
